<!DOCTYPE html>
<html>

<head>
    <title>我的消息</title>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="stylesheet" href="/js/bootstrap/css/bootstrap.min.css">
    <link rel="stylesheet" href="/js/bootstrap/css/bootstrap.css">
    <script src="/js/jquery/jquery.min.js"></script>
    <script src="/js/bootstrap/js/bootstrap.min.js"></script>
    <script src="/js/common.js"></script>
    <link rel="stylesheet" href="/css/font/css/font-awesome.min.css"/>
    <link rel="stylesheet" href="/css/reset.css"/>
    <link rel="stylesheet" href="/css/message.css"/>
    <script>
        var id = getParams().id;
        var types = getParams().type;
        var Html;
        $(function () {
            var li =$(".list-group li:first").clone(true);
            $.get("/"+types,{id:id},function (data) {
                console.log(data);
                $.each(data,function (index, ele) {
                    var row = li.clone(true);
                    Html = "<i style=\"color: #c82333\">"+ele.user1Id.nickName+"</i>私信了你" +
                        " <span class='badge badge-danger badge-pill' style='float: right'>"+ele.nums+"</span>";
                    Html = Html + "<p></p><p> 内容:"+ele.msg.split("&")[0]+"</p>";
                    Html = Html +"<p style='float: right;margin-right: 5px'>"+ele.time+"</p>";
                    row.find("span")[0].innerHTML=Html;
                    row.data("userId",ele.user2Id.id);
                    row.data("id",ele.user1Id.id);

                    row.appendTo(".list-group");
                })
            })
            $(".list-group li:first").remove();

            //绑定私信按钮事件
            $("ul").on("click", ".msgLi", function () {
                //向服务器发送开启私信的请求
                $.get("/letters/" + $(this).data("userId") + "/" + $(this).data("id"),function (data) {
                    var user1 = JSON.stringify(data.user1);
                    var user2 = JSON.stringify(data.user2);
                    sessionStorage.setItem("user1",user1);
                    sessionStorage.setItem("user2",user2);
                    location.href = "/mine/letter.html";
                })
            });
        })
    </script>
</head>

<body>
<div class="search-head">
    <div class="row nav-search">
        <div class="col">
            <a href="javascript:history.go(-1);">
                <span><i class="fa fa-chevron-left"></i></span>
            </a>
        </div>
        <div class="col">
            <span>我的消息</span>
        </div>
        <div class="col"></div>
    </div>
</div>

<ul class="list-group">
    <li class="list-group-item d-flex justify-content-between align-items-center msgLi">
        <div class="item">
            <span>
                <i style="color: #c82333">***</i>私信了你
                <p style="text-align: center">****</p>
            </span>
        </div>
    </li>
</ul>
</body>

</html>